package com.ruoyi.web.controller.qiushi.equipment;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qiushi.domain.dto.DeviceDto;
import com.ruoyi.qiushi.domain.equipment.QiushiDevice;
import com.ruoyi.qiushi.domain.equipment.QiushiDeviceIn;
import com.ruoyi.qiushi.domain.equipment.QiushiDeviceType;
import com.ruoyi.qiushi.service.equipment.IQiushiDeviceInService;
import com.ruoyi.qiushi.service.equipment.IQiushiDeviceService;
import com.ruoyi.qiushi.service.equipment.IQiushiDeviceTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备入库Controller
 *
 * @author ruoyi
 * @date 2023-12-22
 */
@RestController
@RequestMapping("/qiushi/equipment/qiushidevicein")
public class QiushiDeviceInController extends BaseController {
    @Autowired
    private IQiushiDeviceInService qiushiDeviceInService;
    @Autowired
    private IQiushiDeviceTypeService qiushiDeviceTypeService;

    /**
     * 查询设备入库列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushidevicein:list')")
    @GetMapping("/list")
    public TableDataInfo list(QiushiDeviceIn qiushiDeviceIn) {
        startPage();
        List<QiushiDeviceIn> list = qiushiDeviceInService.selectQiushiDeviceInList(qiushiDeviceIn);
        return getDataTable(list);
    }

    /**
     * 导出设备入库列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushidevicein:export')")
    @Log(title = "设备入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QiushiDeviceIn qiushiDeviceIn) {
//        List<QiushiDeviceIn> list = qiushiDeviceInService.selectQiushiDeviceInList(qiushiDeviceIn);

        List<DeviceDto> deviceDtoList = new ArrayList<>();
        deviceDtoList.add(new DeviceDto("#####", "血氧设备", "#####"));
        deviceDtoList.add(new DeviceDto("#####", "血压设备", "#####"));

        ExcelUtil<DeviceDto> util = new ExcelUtil<DeviceDto>(DeviceDto.class);
        util.exportExcel(response, deviceDtoList, "设备入库数据");
    }

    /**
     * 获取设备入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushidevicein:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qiushiDeviceInService.selectQiushiDeviceInById(id));
    }

    /**
     * 新增设备入库
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushidevicein:add')")
    @Log(title = "设备入库", businessType = BusinessType.INSERT)
    @PostMapping
    public String add(@RequestBody QiushiDeviceIn qiushiDeviceIn) {
        qiushiDeviceIn.setUpdateTime(new Date());
//        return toAjax(qiushiDeviceInService.insertQiushiDeviceIn(qiushiDeviceIn));
        return qiushiDeviceInService.insertQiushiDeviceIn(qiushiDeviceIn);
    }

    /**
     * 修改设备入库
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushidevicein:edit')")
    @Log(title = "设备入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QiushiDeviceIn qiushiDeviceIn) {
        qiushiDeviceIn.setUpdateTime(new Date());
        return toAjax(qiushiDeviceInService.updateQiushiDeviceIn(qiushiDeviceIn));
    }

    /**
     * 删除设备入库
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushidevicein:remove')")
    @Log(title = "设备入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(qiushiDeviceInService.deleteQiushiDeviceInById(id));
    }
}
